package cn.well.cloud.config;

import cn.well.cloud.base.warpper.factory.MapWrapperFactory;
import cn.well.cloud.sys.core.properties.BeetlProperties;
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 * @description: 项目中的配置
 * @author: jiawei
 * @create: 2020-10-13 17:30
 */
@Configuration
public class WellPropertiesConfig {

    /**
     * beetl模板的配置
     *
     * @author fengshuonan
     * @Date 2019-06-13 08:55
     */
    @Bean
    @ConfigurationProperties(prefix = BeetlProperties.BEETLCONF_PREFIX)
    public BeetlProperties beetlProperties() {
        return new BeetlProperties();
    }

    /**
     *
     * 处理mybatis 返回数据非驼峰问题
     * 使用默认的SqlSessionFactory时，该类自动加载生效
     * 重写SqlSessionFactory时，configuration需在在自定义SqlSessionFactory时，重新配置如下
     * sqlSessionFactoryBean.getObject().getConfiguration().setObjectWrapperFactory(new MapWrapperFactory());
     * Created by wison on 2019年8月26日.
     * @return
     */
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer(){
        return new ConfigurationCustomizer() {
            @Override
            public void customize(org.apache.ibatis.session.Configuration configuration) {
                configuration.setObjectWrapperFactory(new MapWrapperFactory());
            }
        };
    }

}
